Skip to content

feat(algorithms, dynamic programming): coin change#162

Merged
BrianLusina merged 5 commits into
mainfrom
feat/algorithms-dynamic-programming-coin-change
Jan 25, 2026
Merged

feat(algorithms, dynamic programming): coin change#162
BrianLusina merged 5 commits into
mainfrom
feat/algorithms-dynamic-programming-coin-change

Conversation

@BrianLusina
Copy link
Copy Markdown
Owner

@BrianLusina BrianLusina commented Jan 25, 2026

Describe your change:

Coin Change algorithm problem

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary by CodeRabbit

  • New Features

    • Coin Change added under Dynamic Programming with multiple solution approaches.
    • Climb Stairs now exposes explicit bottom-up and top-down dynamic approaches.
  • Tests

    • Parameterized tests added for Climb Stairs across implementations.
    • New comprehensive test suite for Coin Change algorithms.
  • Chores / Reorganization

    • Coin Change moved from Puzzles to Dynamic Programming and related puzzle artifacts removed.
  • Documentation

    • Detailed Coin Change README added.

✏️ Tip: You can customize this high-level summary in your review settings.

@BrianLusina BrianLusina self-assigned this Jan 25, 2026
@BrianLusina BrianLusina added enhancement Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates Backtracking Backtracking Algorithm Array Array data structure Dynamic Programming Dynamic Programming algorithm labels Jan 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 25, 2026

Warning

Rate limit exceeded

@BrianLusina has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Rehomes Coin Change from puzzles to algorithms/dynamic_programming with three implementations and tests; refactors climb_stairs to expose explicit bottom-up and top-down DP functions and consolidates tests into parameterized suites. Legacy puzzles coin_change module, README, and tests were removed.

Changes

Cohort / File(s) Summary
Directory update
DIRECTORY.md
Added Coin Change under Dynamic Programming and removed the puzzles test entry.
Climb Stairs
algorithms/dynamic_programming/climb_stairs/__init__.py, algorithms/dynamic_programming/climb_stairs/test_climb_stairs.py
Replaced climb(n) with climb_stairs_dp_bottom_up(n) and climb_stairs_dp_top_down(n) (implementations + doctests). Tests converted to parameterized cases covering legacy and new APIs. Note: public API name change.
Coin Change (new)
algorithms/dynamic_programming/coin_change/__init__.py, algorithms/dynamic_programming/coin_change/test_coin_change.py, algorithms/dynamic_programming/coin_change/README.md
New DP package: find_minimum_coins(total_change, coins) (brute-force), coin_change(coins, total) (iterative DP), coin_change_dp(coins, total) (top-down memoized). Added README and parameterized tests including error-case assertions. Review: algorithm correctness, edge-case handling, and test expectations.
Legacy puzzles removal
puzzles/coin_change/__init__.py, puzzles/coin_change/README.md, tests/puzzles/test_coin_change.py
Removed legacy puzzles implementation, README, and tests for coin change. Attention: ensure no remaining imports/reference to removed module.

Sequence Diagram(s)

(Skipped — changes do not introduce multi-component sequential flows that require visualization.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through code with tiny feet,
Coins moved to DP, a tidy feat,
Stairs now climb both up and down,
Tests all passing, no more frown,
A rabbit cheers with carrot sweet 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a Coin Change algorithm to the dynamic programming module.
Description check ✅ Passed The description is complete with all required sections filled out and most checklist items marked as done, indicating thorough adherence to contribution guidelines.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Fix all issues with AI agents
In `@algorithms/dynamic_programming/climb_stairs/__init__.py`:
- Around line 16-27: The bottom‑up function climb_stairs_dp_bottom_up can
IndexError for n <= 0; add an early input guard that mirrors the top‑down base
cases: if n <= 0 return 0, if n == 1 return 1 (and optionally if n == 2 return
2) before allocating dp, so subsequent dp[1]/dp[2] assignments are safe; update
climb_stairs_dp_bottom_up to validate n and return the correct base values.

In `@algorithms/dynamic_programming/coin_change/__init__.py`:
- Around line 10-41: The function find_minimum_coins incorrectly uses
range(total_change) so it never considers combinations of length total_change
and also calls min(coins) without handling an empty coins list; update logic in
find_minimum_coins to first check if coins is empty and raise a clear
ValueError, then iterate combination lengths from 1 up to and including
total_change (e.g., range(1, total_change + 1)) so solutions like
total_change=1, coins=[1] are tried; remove or stop relying on the unused result
variable and ensure the function still raises ValueError when no combination
sums to total_change.

In `@algorithms/dynamic_programming/coin_change/README.md`:
- Line 74: Change the heading text "Step by Step solution construction" to use
the compound modifier form "Step-by-step solution construction" by updating that
heading string in the README (the heading line currently reads Step by Step
solution construction).

In `@algorithms/dynamic_programming/coin_change/test_coin_change.py`:
- Around line 28-30: The test signature for test_find_minimum_coins incorrectly
types the expected parameter as int even though find_minimum_coins returns a
List[int]; update the type hint for the expected parameter in
test_find_minimum_coins from int to List[int] (ensure List is imported if
needed) so the test signature matches the actual return type of
find_minimum_coins.

In `@DIRECTORY.md`:
- Around line 60-61: The "Coin Change" list entry and its nested link "[Test
Coin
Change](https://github.com/BrianLusina/PythonSnips/blob/master/algorithms/dynamic_programming/coin_change/test_coin_change.py)"
are mis-indented; fix MD007 by adjusting the indentation to match the
repository's 2-space nesting convention so the parent bullet and its child link
align (e.g., ensure the nested link is indented two spaces under the "Coin
Change" bullet). Locate the "Coin Change" bullet and its nested link in
DIRECTORY.md and re-indent those lines to the correct 2-space nesting level.
🧹 Nitpick comments (4)
algorithms/dynamic_programming/climb_stairs/__init__.py (1)

30-50: Add memoization so this is truly top‑down DP.

Without caching, this is exponential and defeats the DP intent. Memoizing results makes it O(n).

♻️ Suggested fix (with caching)
+from functools import lru_cache
+
 def climb_stairs(n: int) -> int:
     if n == 1:
         return 1
@@
-def climb_stairs_dp_top_down(n: int) -> int:
+@lru_cache(maxsize=None)
+def climb_stairs_dp_top_down(n: int) -> int:
algorithms/dynamic_programming/climb_stairs/test_climb_stairs.py (1)

9-15: Replace the duplicate case with a base‑case check.

(4, 5) appears twice; swapping one for (1, 1) adds useful coverage without increasing test count.

🧪 Suggested update
 CLIMB_STAIRS_TEST_CASES = [
+    (1, 1),
     (2, 2),
     (3, 3),
     (4, 5),
-    (4, 5),
     (5, 8),
 ]
algorithms/dynamic_programming/coin_change/__init__.py (1)

77-98: Verify Python version for int | float type union.

int | float requires Python 3.10+. If the repo supports older versions, use Union[int, float].

✅ Compatibility‑safe typing
-from typing import List
+from typing import List, Union
@@
-    counter: List[int | float] = [float("inf")] * total
+    counter: List[Union[int, float]] = [float("inf")] * total
algorithms/dynamic_programming/coin_change/test_coin_change.py (1)

10-23: Add a smallest‑nonzero test case.

A total_change=1 case catches off‑by‑one errors in brute‑force search.

🧪 Suggested test addition
 FIND_MINIMUM_COINS_TEST_CASES = [
+    (1, [1, 5, 10, 25, 100], [1]),
     (25, [1, 5, 10, 25, 100], [25]),
     (15, [1, 5, 10, 25, 100], [5, 10]),

Comment thread algorithms/dynamic_programming/climb_stairs/__init__.py
Comment thread algorithms/dynamic_programming/coin_change/__init__.py
Comment thread algorithms/dynamic_programming/coin_change/README.md Outdated
Comment thread algorithms/dynamic_programming/coin_change/test_coin_change.py
Comment thread DIRECTORY.md
BrianLusina and others added 2 commits January 25, 2026 13:15
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions github-actions Bot force-pushed the feat/algorithms-dynamic-programming-coin-change branch from fd1848f to c80e003 Compare January 25, 2026 10:16
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BrianLusina BrianLusina merged commit 95377e8 into main Jan 25, 2026
4 of 6 checks passed
@BrianLusina BrianLusina deleted the feat/algorithms-dynamic-programming-coin-change branch February 20, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Array Array data structure Backtracking Backtracking Algorithm Datastructures Datastructures Documentation Documentation Updates Dynamic Programming Dynamic Programming algorithm enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant